package com.martini.satoken01.service;

import org.springframework.beans.factory.NoSuchBeanDefinitionException;

import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;

/**
 * 默认登录信息缓存服务，二维码登录，邮箱验证信息，待实现
 *
 * @author martini at 2021/12/18 22:01
 */
public class DefaultLoginInfoCacheServiceImpl implements LoginInfoCacheService {

    private final ConcurrentHashMap<Object, Object> cache = new ConcurrentHashMap<>(16);

    @Override
    public String info() {
        return "defaultLoginInfoCacheService";
    }

    @Override
    public void put(Object key, Object value) {
        this.cache.put(key, value);
    }

    @Override
    public void put(Object key, Object value, long timeout, TimeUnit timeUnit) {

    }

    @Override
    public Object get(Object key) {
        return this.get(key, Object.class);
    }

    @Override
    @SuppressWarnings("all")
    public <T> T get(Object key, Class<T> classType) {
        Object obj = this.cache.get(key);
        if (obj != null && (classType == null || !classType.isInstance(obj))) {
            throw new NoSuchBeanDefinitionException("类型未定义异常", "类型未定义异常");
        }
        return obj == null ? null : (T) obj;
    }

    @Override
    public Long listLeftPush(String key, Object value) {
        return null;
    }

    @Override
    public List<Object> listRange(String key, long start, long end) {
        return null;
    }

    @Override
    public <T> List<T> listRange(String key, long start, long end, Class<T> classType) {
        return null;
    }

    @Override
    public <T> T listIndex(String key, long index, Class<T> classType) {
        return null;
    }

    @Override
    public Long listRemove(String key, long count, Object obj) {
        return null;
    }
}
